/**
 * Copyright (C), 2020-2020,贵州铭明网络科技有限公司
 * FileName: PositionInfoController
 * Author:   杨朝湖
 * Date:     2020/12/8 15:47
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.mm.controller;

import com.mm.bo.InsertPosiInfoBo;
import com.mm.bo.PosiListInfoBo;
import com.mm.bo.PosiUpdateBo;
import com.mm.exception.CustomException;
import com.mm.service.PositionInfoService;
import com.mm.util.GetHeadUtil;
import com.mm.util.PageUtil;
import com.mm.util.ResultUtil;
import com.mm.vo.PosiListInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Gym
 * @create 2020/12/8
 * @since 1.0.0
 */
@Api(tags = "用于职位管理的接口")
@RestController
public class PositionInfoController {
    @Resource
    private PositionInfoService positionInfoService;

    @ApiOperation(value = "添加职位信息", notes = "添加职位信息", httpMethod = "POST")
    @PostMapping("/v1/posi/insertPosiInfo")
    public ResultUtil<Object> insertPosiInfo(@RequestBody @Valid InsertPosiInfoBo insertPosiInfoBo) {
        insertPosiInfoBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = positionInfoService.insertPosiInfo(insertPosiInfoBo);
        if (row < 1) {
            throw new CustomException("添加职位失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "查询职位列表", notes = "查询职位列表", httpMethod = "POST")
    @PostMapping("/v1/posi/queryPosiList")
    public ResultUtil<Object> queryPosiList(@RequestBody @Valid PosiListInfoBo posiListInfoBo) {
        PageUtil<PosiListInfoVo> posiListInfoVoPageUtil = positionInfoService.queryPosiList(posiListInfoBo);
        return ResultUtil.success(posiListInfoVoPageUtil);
    }

    @ApiOperation(value = "修改职位信息", notes = "修改职位信息", httpMethod = "POST")
    @PostMapping("/v1/posi/updatePosiInfo")
    public ResultUtil<Object> updatePosiInfo(@RequestBody @Valid PosiUpdateBo posiUpdateBo) {
        posiUpdateBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = positionInfoService.updatePosiInfo(posiUpdateBo);
        if (row < 1) {
            throw new CustomException("修改职位失败");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "修改职位信息", notes = "修改职位信息", httpMethod = "GET")
    @GetMapping("/v1/posi/deletePosiInfo/{posiId}")
    public ResultUtil<Object> deletePosiInfo(@PathVariable("posiId") String posiId) {
        Integer row = positionInfoService.deletePosiInfo(posiId, GetHeadUtil.getHeadToken());
        if (row < 1) {
            throw new CustomException("删除职位失败");
        }
        return ResultUtil.success(null);
    }
}